package com.shujia.controller;

import com.shujia.entity.Dept;
import com.shujia.service.DeptService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

//如果在使用Controller的时候，还想在方法返回数值的时候，需要再与ResponseBody配合使用
@Controller
//@ResponseBody
public class DeptControlle {

    @Autowired
    private DeptService deptService;

    //声明日志成员
    private static final Logger log = LoggerFactory.getLogger(DeptControlle.class);

    @RequestMapping("all")
    public String showAllDept(Model model){
        List<Dept> list = deptService.getAllCusBaseInfo();

        model.addAttribute("depts",list);

//        return deptService.getAllCusBaseInfo();
        return "showall";
    }

    //http://localhost:8089/bigdata19-dev/save?deptno=102&dname=测试部3&loc=马鞍山独立营3
    @RequestMapping("save")
    public String saveDept(int deptno,String dname,String loc){
        Dept dept = new Dept(deptno, dname, loc);
        return deptService.saveDeptInfo(dept);
    }

    //根据部门编号查询某一个部门信息
    @RequestMapping("selectOne")
    public String selectOneDept(int deptno,Model model){
        Dept deptByNo = deptService.getDeptByNo(deptno);
        model.addAttribute("name","小虎");
        model.addAttribute("name2","<a href='www.baidu.com'>张三</a>");
        model.addAttribute("username","小陈");
        model.addAttribute("dept",deptByNo);

        log.info("=================这是info级别的日志========================");
//        return deptService.getDeptByNo(deptno);
        return "index";
    }

    @RequestMapping("hello2")
    public String hello(Model model){
        System.out.println("测试与 thymeleaf 的集成");
        model.addAttribute("name","小虎");
        model.addAttribute("name2","<a href='www.baidu.com'>张三</a>");
        model.addAttribute("username","小陈");

        return "index";
    }

}
